 <?php
class CompanyPromotion extends CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return "mt_company_promotion";
    }
    
    public function attributeLabels() {
        return array(
            "company_promotion_name" => "ชื่อโปรโมชั่น",
            "company_promotion_description" => "รายละเอียดโปรโมชั่น",
            "company_promotion_status" => "สถานะ",
            "company_promotion_create_date" => "วันที่สร้าง",
            "company_promotion_modified_date" => "วันที่แก้ไข",
        );
    }
    
    public function rules() {
        return array(
            array("company_promotion_name, company_promotion_description", "required",'message'=>'กรุณากรอกข้อมูลให้ครบ'),
            array("company_promotion_name", "length", "max" => 255),
            array("company_promotion_description", "length", "max" => 255),
        );
    }
    
    public function search() {
        $criteria = new CDbCriteria;
        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }
    
    public function beforeValidate() {
        if ($this->isNewRecord) {
            $this->company_promotion_status = 1;
            $this->company_promotion_create_date = new CDbExpression("NOW()");
        }
        else
        {
            $this->company_promotion_modified_date = new CDbExpression("NOW()");
        }

        return parent::beforeValidate();
    }
}
?>
